package com.plan.service.card.impl;

import com.plan.base.constant.BaseCode;
import com.plan.base.entity.Result;
import com.plan.controller.card.request.BaseReq;
import com.plan.controller.card.request.UpdateLotteryRateReq;
import com.plan.dao.service.card.PointPrizeDrawSettingDaoService;
import com.plan.entity.card.PointPrizeDrawSetting;
import com.plan.enums.DelFlagEnum;
import com.plan.service.card.PointPrizeDrawSettingService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
public class PointPrizeDrawSettingServiceImpl implements PointPrizeDrawSettingService {
    @Resource
    private PointPrizeDrawSettingDaoService pointPrizeDrawSettingDaoService;


    @Override
    public Result<Long> updateLotteryRate(UpdateLotteryRateReq req) {
        pointPrizeDrawSettingDaoService.update(req);
        return Result.ok(req.getTeamId());
    }

    @Override
    public Result<Integer> getSpendPoint(BaseReq req) {
        PointPrizeDrawSetting old = pointPrizeDrawSettingDaoService.getOneByTeamId(req.getTeamId());
        if (old == null) {
            // 没有就新增一个
            PointPrizeDrawSetting setting = new PointPrizeDrawSetting();
            setting.setSpendPoint(20);
            setting.setCreatorId(0L);
            setting.setUpdaterId(0L);
            setting.setTeamId(req.getTeamId());
            setting.setDelFlag(DelFlagEnum.NORMAL.getType());
            pointPrizeDrawSettingDaoService.insert(setting);
            return Result.ok(setting.getSpendPoint());
        }
        return Result.ok(old.getSpendPoint());
    }

}
